{template header}
<link rel="stylesheet" href="static/calendar/js/calendar.css" />
<script type="text/javascript" charset="utf-8" src="static/calendar/calendar.php"></script>

<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<script charset="utf-8" src="/static/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh_CN.js"></script>

<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
    .form-horizontal{height:initial}
    .suggest {position: absolute;border:1px solid blue;background-color: #fff;width:210px;margin:0px;padding:5px;line-height: 22px;}
    .suggest div{height:22px;overflow: hidden}
</style>
<h4 style="padding-left:10px;;">
    <a href="?c=adminFlashBuy&a=getFlashList"><span>商品列表</span></a>
    >>
</h4>
<script type="text/javascript">
    function uploadImage() {
        if($("#imgFile").val() != '') $("#upload_form").submit();
    }
    function upload_frame_load() {
        var data = $(window.frames['upload_frame'].document.body).html();
        if(data) {
            data = eval('(' + data + ')');
            //console.log(data);return false;
            if(data.status=='ok'){
                var _this= $('#showImage');_num = _this.find('img').length;
                var _html = '';
                if (_num && (_num % 5) == 0) {
                    _html +='<br />';
                }
                 _html +=
                        '<span style="margin: 10px  10px 10px 10px">'
                        +'<img src="'+ data.image+'" style="width: 100px;height: 100px;">'
                        +'<input type="hidden" name="image[]" value="'+data.image+'" />'
                        +'</span>'
                        +'<span class="btn btn-primary delimages" >删除</span>';

                $('#showImage').append(_html);
            }else{
                alert(data.error_msg);
            }
        }
    }
    var editor;
    $(function () {
         KindEditor.ready(function (K) {
             editor = K.create('textarea[name="introduce"]', {
                allowFileManager: true,
                uploadJson: './index.php?c=admin&a=uploadKindEditorImg',
                newlineTag: 'p',
                filterMode: true,
                height:400,
                htmlTags: {
                    p: ['style', 'color', 'align', 'class'],
                    font: ['style', 'color', 'size', 'face', 'class'],
                    span: ['style', 'style', 'color', 'align'],
                    div: ['style', 'class', 'align'],
                    a: ['style', 'class', 'href', 'target', 'name'],
                    embed: ['style', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality',
                        'style', 'align', 'allowscriptaccess', '/'],
                    img: [ 'src', 'border', 'alt', 'title', 'align', 'data-source', '/', 'class'],
                    hr: ['style', 'class', '/'],
                    br: ['/'],
                    'ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': ['style', 'align'],
                    'tbody,tr,strong,b,sub,sup,em,i,u,strike,section': ['style', 'class'],
                },
                afterBlur: function () {
                    this.sync();
                }
            });
            /*
            K.create('textarea[name="introduce2"]', {
                allowFileManager: true,
                uploadJson: './index.php?c=admin&a=uploadKindEditorImg',
                newlineTag: 'p',
                filterMode: true,
                htmlTags: {
                    p: ['style', 'color', 'align', 'class'],
                    font: ['style', 'color', 'size', 'face', 'class'],
                    span: ['style', 'style', 'color', 'align'],
                    div: ['style', 'class', 'align'],
                    a: ['style', 'class', 'href', 'target', 'name'],
                    embed: ['style', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality',
                        'style', 'align', 'allowscriptaccess', '/'],
                    img: ['style', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', 'data-source', '/', 'class'],
                    hr: ['style', 'class', '/'],
                    br: ['/'],
                    'ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': ['style', 'align'],
                    'tbody,tr,strong,b,sub,sup,em,i,u,strike,section': ['style', 'class'],
                },
                afterBlur: function () {
                    this.sync();
                }
            });
            */
        });
    })

</script>
<div id="fream">
    <form id="upload_form" method="post" action="?c=adminFlashBuy&a=ajaxUploadImage" target="upload_frame" enctype="multipart/form-data">
        <input type="file" name="imgFile" id="imgFile" style="display:none;" onchange="uploadImage();">
    </form>
    <iframe id="upload_frame" name="upload_frame" style="display:none" onLoad="upload_frame_load();"></iframe>
</div>
<form class="form-horizontal"  action="?c=adminFlashBuy&a=ajaxAddFlashBuy"  id="tr_form">
    <div class="control-group" style="display: none">
        <label class="control-label">ID：</label>
        <div class="controls">
            {$flashId}
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >状态：</label>
        <div class="controls">
            <select name="status">
            {loop $flashSaleStatus $k $v}
            <option value="{$k}" {if isset($flashInfo['status']) && $flashInfo['status']==$k}selected{/if}>{$v}</option>
            {/loop}
            </select>
        </div>
    </div>


    <div class="control-group">
        <label class="control-label" >标题：</label>
        <div class="controls">
            <input type="text" style="width:400px;" value="{if isset($flashInfo['title'])}{$flashInfo['title']}{/if}" name="name" placeholder="请输入标题" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >  图片：</label>
        <div class="controls">
            <button type="button" id="file_upload_btn" class="btn btn-primary" onclick="$('#imgFile').trigger('click')">
                <i class="ace-icon fa fa-cloud-upload bigger-110"></i>上传图片
            </button>
            <span style="color:rebeccapurple">*可上传多张,尺寸建议为等比宽高,如:400x400,800x800</span>
        </div>
    </div>
    <div class="control-group">
        <div class="controls" id="showImage">
            {if isset($flashInfo['images'])}
                {loop $flashInfo['images'] $k $v}
                <span style="margin: 10px  10px 10px 10px">
                 <img src="{$v}" style="width: 100px;height: 100px;">
                 <input type="hidden" name="image[]" value="{$v}" />
                </span>
                <span class="btn btn-primary delimages" >删除</span>
                {/loop}
            {/if}
        </div>
    </div>
    <div class="control-group" style="display: none;">
        <label class="control-label" >类型：</label>
        <div class="controls">
            <select name="type" id="type" readonly="readonly" disabled="disabled">
                <option value="1" {if isset($flashInfo['type'])&&$flashInfo['type'] == 1}selected{/if}>自营团购</option>
                <option value="2" {if isset($flashInfo['type'])&&$flashInfo['type'] == 2}selected{/if}>识货团购</option>
                <option value="3" {if isset($flashInfo['type'])&&$flashInfo['type'] == 3}selected{/if}>直卖</option>
            </select>
        </div>

    </div>

    <script>
        $('#type').on('change',function(){
            var val = $(this).val();
            hiddenDiv(val);
        })
        function hiddenDiv(val){
            if(val==1){
                $('._hidden_control').css('display','block');
                $('._hidden_shihuo').css('display','none');
            } else if(val==2){
                $('._hidden_control').css('display','block');
                $('._hidden_shihuo').css('display','');
            }else if(val==3){
                $('._hidden_control').css('display','none');
                $('._hidden_shihuo').css('display','none');
            }
        }
        //hiddenDiv($("#type").val());
    </script>
    <div class="control-group" style="display: none">
        <label class="control-label" >最低成本价：</label>
        <div class="controls">
            {$low_first_cost}
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >售卖价格：</label>
        <div class="controls">
            ￥<input type="text" style="width: 50px;" value="{if isset($flashInfo['low_price'])}{$flashInfo['low_price']}{/if}" name="low_price" placeholder="仅用于前端展示，无其他作用" />
             <span style="color:#666">
                 &nbsp;&nbsp;&nbsp;官方建议零售价：
                ￥<input type="text" style="width: 50px;" value="{if isset($flashInfo['cost_price'])}{$flashInfo['cost_price']}{/if}" name="costPrice" placeholder="仅用于前端展示，无其他作用" />
             </span>
        </div>
    </div>
    <div class="control-group" style="display: none">
        <label class="control-label" >最低团购价：</label>
        <div class="controls" id="low_price">
            
        </div>
    </div>
    <h4>其它</h4>
    <div class="control-group _hidden_control" style="display: none;">
    <label class="control-label" >预热开始：</label>
    <div class="controls">
        <input type="text" name="preHotTime" id="date_time_id3" value="{if isset($flashInfo['formatPreHotTime'])}{$flashInfo['formatPreHotTime']}{/if}">　
        <button name="date_time_btn2" type="button" id="date_time_btn3" onclick="return showCalendar('date_time_id3', '%Y-%m-%d %H:%M:%S', '24', false, 'date_time_btn3');" class="button" id="date_time_id3"/>选择</button>
    </div>
    </div>
    <div class="control-group _hidden_control">
    <label class="control-label" >开售时间：</label>
    <div class="controls">
        <input type="text" name="startTime" id="date_time_id" value="{if isset($flashInfo['formatStartTime'])}{$flashInfo['formatStartTime']}{/if}">　
        <button name="date_time_btn" type="button" id="date_time_btn" onclick="return showCalendar('date_time_id', '%Y-%m-%d %H:%M:%S', '24', false, 'date_time_btn');" class="button" id="date_time_id"/>选择</button>
        至
        <input type="text" name="endTime" id="date_time_id2" value="{if isset($flashInfo['formatEndTime'])}{$flashInfo['formatEndTime']}{/if}">　
        <button name="date_time_btn2" type="button" id="date_time_btn2" onclick="return showCalendar('date_time_id2', '%Y-%m-%d %H:%M:%S', '24', false, 'date_time_btn2');" class="button" id="date_time_id2"/>选择</button>
        <br><span style="color:rebeccapurple">*结束时间不填,则商品为直卖商品,不在团购列表中出现</span>

    </div>
    </div>
     <div class="control-group">
        <label class="control-label" >关联装备ID：</label>
        <div class="controls">
            <input type="text" autocomplete="off" id="gear_id" value="{if isset($flashInfo['gear_id'])}{$flashInfo['gear_id']}{/if}" name="gear_id" placeholder="请输入装备ID" />
            <span></span>
        </div>
    </div>
    <script>
        $('#gear_id').on('keyup',function(){
            var keywords = $(this).val();
            var _this = $(this);

            function render(data){
                if(data.lenth>0) {
                    var arr = [];
                    for (var i = 0; i < data.length; i++) {
                        arr.push('<div did="'+data['id']+'">'+data['name']+'</div>');
                    }
                }else{
                    container.append('<div class="suggest"><div>无结果</div>')
                }
            }
            $.ajax({
                dataType: "json",
                url: '/ajax/adminSearchGear?keywords='+keywords,
                success: function(data){
                    $('.suggest').remove();
                    if(data.length > 0){
                        var arr = [];
                        for (var i = 0; i < data.length; i++) {
                            console.log(i);
                            arr.push('<div did="' + data[i]['id'] + '">' + data[i]['name'] + '</div>');
                        }
                        $(_this).parent().append('<div class="suggest">'+arr.join('')+'</div>')
                        $('.suggest div').on('click',function(){
                            $(_this).val($(this).attr('did'));
                            $(_this).parent().find('span').html($(this).text());
                            $('.suggest').remove();
                        });
                    }else{
                        $(_this).parent().append('<div class="suggest"><div>无结果</div>')
                    }
                }
            });

        });

    </script>
    <div class="control-group" {if $flashInfo['type']!=2}style="display: none;"{/if}>
    <label class="control-label" >识货团购ID：</label>
    <div class="controls">
        <input type="text" readonly="readonly" value="{if isset($flashInfo['shihuo_grouponid'])}{$flashInfo['shihuo_grouponid']}{/if}" name="shihuo_grouponid" />
    </div>
    </div>
    <h4>商品详情</h4>
    <div class="control-group">
        <label class="control-label">图文内容：</label>
        <div class="controls">
            <textarea id="introduce" name="introduce" style="width:800px; height:400x;">
                {if isset($flashInfo['image_content'])}{$flashInfo['image_content']}{/if}
            </textarea>
        </div>
    </div>

    <!--
    <div class="control-group">
        <label class="control-label" >参数规格：</label>
        <div class="controls">
            <textarea rows="10" name="introduce2" style="width:800px; min-height:200x;">
                 {if isset($flashInfo['option_content'])}{$flashInfo['option_content']}{/if}
            </textarea>
        </div>
    </div>
    -->
    
    <div class="control-group" style="display: none;">
        <label class="control-label" >微店链接：</label>
        <div class="controls">
            <input type="text" value="{if isset($flashInfo['weidian_link'])}{$flashInfo['weidian_link']}{/if}" name="weidian_link" placeholder="" />
        </div>
    </div>

    <div class="control-group">
        <div class="controls">
            <input type="hidden" class="inputFlashId" name="flashId" value="{$flashId}"/>
            <span class="btn btn-primary" type="button" id="qd">先保存这里</span>
        </div>
    </div>
</form>

<iframe  id="setgoodsframe" src="{if isset($flashInfo['type']) && $flashInfo['type']!=2  && isset($flashInfo['id'])}?c=adminFlashBuy&a=addFlashGoods&flashId=$flashInfo['id']{/if}" width="100%" height="800" frameborder="0"></iframe>
<script type="text/javascript">
    $(document).on("click",".delimages", function () {
        var _this=$(this),_del = $(this).prev('span');
        _del.remove();
        _this.remove();
    })

    
    $('#qd').on('click',function(){
        $('#introduce').text(editor.html());
        $.ajax({
            type:'POST',
            url:$('#tr_form').attr('action'),
            data:$('#tr_form').serialize(),
            dataType:'json',
            success:function(d){
                if(d.status=='ok' && d.id){
                    alert(d.error_msg);
                    $('.inputFlashId').val(d.id)
                    if($('#type').val()!=2){
                        $('#setgoodsframe').attr('src','?c=adminFlashBuy&a=addFlashGoods&flashId='+d.id);
                    }
                }else{
                    alert(d.error_msg);
                }
            }
        })
    })
</script>

{template footer}

